package com.tzq.bearstory;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.ximalaya.ting.android.opensdk.player.XmPlayerManager;


public class MyPlayerReceiver extends BroadcastReceiver {
    public static final int NOTIFICATION_ID = 611226;
    public static final String NOTIFICATION_CHANNEL_ID = "channel_001";
    public static final String NOTIFICATION_CHANNEL_NAME = "channel_001_name";
    public static final String ACTION_PAUSE_START = "com.bear.story.PLAY_PAUSE_START";
    public static final String ACTION_PLAY = "com.bear.story.PLAY_START";
    public static final String ACTION_PAUSE = "com.bear.story.PLAY_PAUSE";
    public static final String ACTION_NEXT = "com.bear.story.PLAY_NEXT";
    public static final String ACTION_PRE = "com.bear.story.PLAY_PRE";
    public static final String ACTION_CLOSE = "com.bear.story.CLOSE";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
            LogUtils.d("MyPlayerReceiver.onReceive action:" + intent.getAction());
            if (intent.getAction().equals(ACTION_CLOSE)) {
                XmPlayerManager.release();
                System.exit(1);
            } else if (intent.getAction().equals(ACTION_PAUSE_START)) {
                if (XmPlayerManager.getInstance(context).isPlaying()) {
                    LogUtils.d("---pause");
                    XmPlayerManager.getInstance(context).pause();
                } else {
                    LogUtils.d("---play");
                    XmPlayerManager.getInstance(context).play();
                }
            } else if (intent.getAction().equals(ACTION_NEXT)) {
                XmPlayerManager.getInstance(context).playNext();
            } else if (intent.getAction().equals(ACTION_PRE)) {
                XmPlayerManager.getInstance(context).playPre();
            }
        }
    }
}
